﻿Public Class Service1

    Public oTimer_ARinvoice As New System.Timers.Timer


    Protected Overrides Sub OnStart(ByVal args() As String)
        ' Add code here to start your service. This method should set things
        ' in motion so your service can do its work.
        Dim sFuncName As String = String.Empty
        Dim sErrDesc As String = String.Empty
        Dim sQuery As String = String.Empty
        Try
            sFuncName = "OnStart()"

            p_iDebugMode = 1

            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Starting Function", sFuncName)

            oTimer_ARinvoice.Interval = 60000
            oTimer_ARinvoice.Start()

            AddHandler oTimer_ARinvoice.Elapsed, AddressOf TimerCallingFunction_ARInvoice
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Completed with SUCCESS ", sFuncName)

        Catch ex As Exception
            WriteToLogFile(ex.Message, sFuncName)
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Completed with ERROR", sFuncName)
        End Try
    End Sub

    Protected Overrides Sub OnStop()
        ' Add code here to perform any tear-down necessary to stop your service.
        Dim sFuncName As String = String.Empty
        sFuncName = "OnStop()"
        If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Attempting Function ", sFuncName)
        oTimer_ARinvoice.Stop()

    End Sub

    Public Sub New()
        MyBase.New()
        InitializeComponent()
    End Sub

    Private Sub TimerCallingFunction_ARInvoice()

        ' **********************************************************************************
        '   Function    :   TimerCallingFunction_ARInvoice()
        '   Purpose     :   
        '   Author      :   JOHN
        '   Date        :   AUG 2014
        ' **********************************************************************************

        Dim sFuncName As String = String.Empty
        Dim sErrDesc As String = String.Empty
        Dim oARInvoice As clsARInvoice = New clsARInvoice

        Try
            sFuncName = "TimerCallingFunction_ARInvoice"

            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Starting Function ", sFuncName)

            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Calling Create_ARInvoice()", sFuncName)

            If oARInvoice.Create_ARInvoice(sErrDesc) <> RTN_SUCCESS Then Throw New ArgumentException(sErrDesc)

            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Completed with SUCCESS ", sFuncName)

        Catch ex As Exception
            WriteToLogFile(ex.Message, sFuncName)
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Completed with ERROR", sFuncName)
        End Try

    End Sub

End Class
